var _webRoot_Path = "/HyManageSystem";
var modules = [ {
	include : true,
	incfile : _webRoot_Path+'/style/common/reset.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/button_a.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/style/common/list.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_dept_worker.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/common_cw_subject_funds.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/frameworkutil.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/ymPrompt.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/My97DatePicker/WdatePicker.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/ymPrompt4/skin/vista/ymPrompt.css'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.scrollabletable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/webtoolkit.jscrollable.js'
}, {
	include : true,
	incfile : _webRoot_Path+'/js/common/jquery.tablesorter.js'
} ];

for ( var i = 0; i < modules.length; i++) {
	if (modules[i].include === true) {
		filename = modules[i].incfile;
		if (jQuery.browser.safari) {
			jQuery.ajax({
				url : filename,
				dataType : 'script',
				async : false,
				cache : true
			});
		} else {
			var fileType = filename.substring(filename.lastIndexOf('.') + 1,
					filename.length).toUpperCase();
			if (fileType == 'JS') {
				IncludeJavaScript(filename);
			} else if (fileType == 'CSS') {
				IncludeCss(filename);
			}
		}
	}
}

/**
 * 导入JS文件到页面
 * 
 * @param jsFile
 */
function IncludeJavaScript(jsFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oScript = document.createElement('script');
	oScript.type = 'text/javascript';
	oScript.charset = 'utf-8';
	oScript.src = jsFile;
	oHead.appendChild(oScript);
};

/**
 * 导入CSS文件到页面
 * 
 * @param cssFile
 */
function IncludeCss(cssFile) {
	var oHead = document.getElementsByTagName('head')[0];
	var oLink = document.createElement('link');
	oLink.rel = "stylesheet";
	oLink.type = 'text/css';
	oLink.href = cssFile;
	oHead.appendChild(oLink);
};

function showdetail(id){
    try {
    	if (null == id || id <= 0) {
    	        alert("请选择要操作的数据!");
    	        return false;
    	    }
        var result = {
            'id': id
        };
        var url = _webRoot_Path+"/v/ad/getEntity";
        postData(url, result, function(msg){
            if (msg.infoNo == 1) {
                var constObj = eval(msg.myEntity);
                var obj = constObj[0];
                ymPrompt.win({
                    message: $('#showAndUpDetail').html(),
                    width: 600,
                    height: 500,
                    title: '显示和修改任务详细信息'
                });
                $("#ym-window").find("#p_id").val(obj.adId);
                $("#ym-window").find("#p_ad_1").val(obj.conTitle);
                $("#ym-window").find("#p_ad_2").val(obj.adState);
                $("#ym-window").find("#p_ad_3").val(obj.adType);
                $("#ym-window").find("#p_ad_4").val(obj.timeStart);
                $("#ym-window").find("#p_ad_5").val(obj.timeEnd);
                $("#ym-window").find("#p_ad_6").val(obj.timeAways);
                $("#ym-window").find("#p_ad_7").val(obj.dayMaxBuget);
                $("#ym-window").find("#p_ad_8").val(obj.serviceRate);
                $("#ym-window").find("#p_ad_9").val(obj.totalUv);
                $("#ym-window").find("#p_ad_10").val(obj.conCpuv);
                $("#ym-window").find("#p_ad_11").val(getSnsName(obj.pubPlatform));
                $("#ym-window").find("#p_ad_12").val(obj.pvCount);
                $("#ym-window").find("#p_ad_13").val(obj.catalog);
                $("#ym-window").find("#p_ad_14").val(obj.conUrl);
                $("#ym-window").find("#p_ad_15").val(obj.conPic);
                $("#ym-window").find("#p_ad_16").val(obj.conDesc);
                $("#ym-window").find("#p_ad_17").val(obj.conTips);
                $("#ym-window").find("#p_ad_18").val(obj.province);
                $("#ym-window").find("#p_ad_19").val(obj.city);
                $("#ym-window").find("#p_ad_20").val(obj.pubRate);
                $("#ym-window").find("#p_ad_21").val(obj.slgRate);
                $("#ym-window").find("#p_ad_22").val(obj.sort);
                $("#ym-window").find('input:radio[name="p_ad_2"][value=' +
                		obj.adState +
                ']').attr('checked', true);
                $("#ym-window").find('input:radio[name="p_ad_3"][value=' +
                		obj.adType +
                ']').attr('checked', true);
            }
            else {
                alert(msg.infoStr);
            }
        });
        
    } 
    catch (e) {
        alert(e.message);
        return;
    }
}
function getAd(type){
	if(type == 1){
		return "爱心";
	}else if(type == 2){
		return "钻石";
	}else if(type == 3){
		return "皇冠";
	}else if(type == 3){
		return "权杖";
	}
}
function saveEntityByAd(){
	var p_ad_20 = $.trim($("#ym-window").find("#p_ad_20").val());
    if (p_ad_20 == "" || p_ad_20.length <= 0) {
	       alert("请填写发布分成比例");
	       $("#ym-window").find("#p_ad_20").focus();
	       return false;
	 }
	var p_ad_21 = $.trim($("#ym-window").find("#p_ad_21").val());
	if (p_ad_21 == "" || p_ad_21.length <= 0) {
		  alert("请填写文案分成比例");
		  $("#ym-window").find("#p_ad_21").focus();
		  return false;
	 }
    var p_ad_3 = $('input:radio[name="p_ad_3"]:checked').val();
    var p_ad_2 = $('input:radio[name="p_ad_2"]:checked').val();
    var p_id = $("#ym-window").find("#p_id").val();
    var p_ad_9 = $("#ym-window").find("#p_ad_9").val();
    var p_ad_10 = $("#ym-window").find("#p_ad_10").val();
    var p_ad_22 = $("#ym-window").find("#p_ad_22").val();
    var p_ad_7 = $("#ym-window").find("#p_ad_7").val();
    var p_ad_8 = $("#ym-window").find("#p_ad_8").val();
    var result = {
            'p_id': p_id,
            'p_ad_state': p_ad_2,
            'p_ad_pubrate': p_ad_20,
            'p_ad_slgrate': p_ad_21,
            'p_ad_total_uv': p_ad_9,
            'p_ad_con_cpuv': p_ad_10,
            'p_ad_sort': p_ad_22,
            'p_service_rate': p_ad_8,
            'p_dayMax_buget': p_ad_7,
            'p_ad_type': p_ad_3
        };
        var url = _rootPath +"/v/ad/upEntity";
        postData(url, result, function(msg){
            if (msg.infoNo == 1) {
                alert(msg.infoStr);
                window.location.reload();
            }
            else {
                alert(msg.infoStr);
            }
        });
}

function searchData(){
    var p_type = $("#p_type").val();
    var p_state = $("#p_state").val();
    var p_startTime = $("#p_startTime").val();
    var p_endTime = $("#p_endTime").val();
    location.href = _rootPath + "/v/ad/index?p_state=" + p_state +
    "&p_type=" +
    p_type+"&p_endtime=" + p_endTime+
    "&p_starttime=" +
    p_startTime;
  
};
function getSnsType(types){
	if(types == '1'){
		return "新浪";
	}else if(types == '2'){
		return "腾讯";
	}
}
function getSnsName(types){
	var typeName = "";
	var type = types.split(",");
	for (var i = 0; i < type.length; i++) {
		typeName+=getSnsType(type[i]);
		if(i< type.length-1){
			typeName+=","
		}
	}
	return typeName;
}
